<?php
class Relation extends GetData{

	private $daten;
	public $System;
	private $action = array();

	public function __construct($match){
		$this->daten = $match;
	}

	public function getWort(RainTPL $design){	        
		parent::GetData();
		
		if(isset($_SESSION['UserCity'])){
		    $design->assign ('userlocation',$_SESSION['UserCity']);
		}
		$DbUserRelation = new Db_user_relation;
		
	    if(isset($this->daten['freund_id'])){
	        if($DbUserRelation->isOpenRelation($this->daten['freund_id'])){	            
    	        $accept = $DbUserRelation->accept($this->ActivUser->id,$this->daten['freund_id']);
    	        
    	        if($accept){    	            
	                $this->action['aktion'] = 1;
	                $this->action['Text']   = "Freunschafts angebot wurde Angenommen";
    	        }else{    	            
	                $this->action['aktion'] = 0;
	                $this->action['Text']   = "Freunschafts fehl geschlagen";
    	        }
	        }else{
                $this->action['aktion'] = 0;
                $this->action['Text']   = "Fehler";
	        }
	    }
	    
		if($this->action){
		    $design->assign ('action',$this->action);
		}
		
	    $UserRelations = $DbUserRelation->getUserRelation($this->ActivUser->id);		    
	    $RelationInvitations = $DbUserRelation->getRelationInvitation($this->ActivUser->id);

	    if($RelationInvitations){
	        foreach ($RelationInvitations as $key => $RelationInvitation){
	            $user = new Db_User();
	            $Invitation = $user->GetUserByID($RelationInvitation->user_id);
	            $RelationInvitations[$key]->user = $Invitation;
	        }
	        $design->assign ('Invitations',$RelationInvitations);
	        $design->assign ('RelationInvitation',count($RelationInvitations));
	    }
		    
		$design->assign ('UserRelations',$UserRelations);
		    
		$design->assign ('css',"Srelation");
		$design->assign ('js',"jsSrelation");		
		

		if( $cache = $design->cache( $design->ln.'/setting/relation', $expire_time = 0 ) )
	    {
	 	    echo $cache;
	    }
	    else
	    {
	 	    $design->draw( $design->ln.'/setting/relation' );
	    }
	}

}
?>